package com.focus.xyz.union.pages.frontend;

import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.pages.BaseMenu;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import java.util.List;

/**
 * Created by chenmeng on 2016/4/18.
 */
public class FrontMenuList extends BaseMenu{
    private Action action;
    @FindBy(id = "dev_myUnion_sideNav")
    private WebElement menu;
    private static final String MENU_XPATH = "dd/a";

    public FrontMenuList(WebDriver driver, Action action){
        super(driver,action);
        this.action = action;
        PageFactory.initElements(driver,this);
    }

    @Override
    protected void openExpandMenu(String pName, String name) throws Exception {

    }




    /*
    * 根据链接名称打开链接，适用于渠道前台打开菜单操作
    * */
    @Override
    public void openMenu(String linkText) throws Exception{
        List<WebElement> menuList = menu.findElements(By.xpath(MENU_XPATH));
        for(WebElement menu:menuList){
            if(linkText.equals(menu.getText().trim())){
                action.click(menu);
                action.waitForPageLoad();
                break;
            }
        }

    }
}
